import pandas as pd
import os
import numpy as np


folder_path = 'D:\\accessability\\ACCESSIBILITY_RESULTS\\Model_Experiment_Result_Raw_Data'

#The list of the model name and the language
themes = [ "GPT4.1_CHINESE", "GPT4.1_ENGLISH", "Gemini_1.5_Pro_CHINESE", "Gemini_1.5_Pro_ENGLISH","GPT4O_CHINESE", "GPT4O_ENGLISH",
    "CLAUDE_CHINESE", "CLAUDE_ENGLISH","LLAMA4_CHINESE", "LLAMA4_ENGLISH", "QWEN_CHINESE", "QWEN_ENGLISH"
]

#A list to store data
statistics = []

# process each theme
for theme in themes:
    correct_list = []
    
    # ten run
    for run in range(1, 11):
        correct_count = 0
        total_count = 0
        file_name = f"{theme}_for_questions_answers_run_{run}.csv"
        file_path = os.path.join(folder_path, file_name)
        
        if os.path.exists(file_path):
            df = pd.read_csv(file_path)
            # The experiment group spans from 0 to 60.
            # The control groups are divided into three intervals: 
            # only pronoun 60–120, pronoun+reinforcing demonstratives 120–180, pronoun+inconsistent demonstratives 180–240 
            df = df.iloc[0:60].reset_index(drop=True)
            for i in range(len(df)):
                if df.loc[i, 'Comparison'] == 1:
                    correct_count += 1
                total_count += 1

        if total_count > 0:
            correct_list.append(correct_count / total_count)
    
    # count
    if correct_list:
        average = np.mean(correct_list)
        std_dev = np.std(correct_list)
        max_value = np.max(correct_list)
        min_value = np.min(correct_list)
        
        statistics.append({
            "Theme": theme,
            "Average ± Std Dev": f"{average:.4f} ± {std_dev:.4f}",
            "Max": max_value,
            "Min": min_value
        })

# Output the statistical data to a new file
output_df = pd.DataFrame(statistics)
output_path="D:\\accessability\\ACCESSIBILITY_RESULTS\\Model_Experiment_Result_Statistics_Data\\Analysis_of_demonstrative_pronoun conditions"
output_file_path = os.path.join(output_path, 'Only_demonstrative_accuracy_statistics.csv')  # Your file name
output_df.to_csv(output_file_path, index=False)

print(f"All statistical data has been computed and saved to the file: {os.path.basename(output_file_path)}")

